<?php
error_reporting(E_ALL|E_STRICT);
date_default_timezone_set('Asia/Shanghai');
set_include_path(get_include_path().PATH_SEPARATOR.
		'./app/models'.PATH_SEPARATOR.
		'./app/views/scripts'.PATH_SEPARATOR.
		'./library');

session_save_path('./tmp');

require_once 'Zend/Loader.php';

// 自动载入包含类$class的.php文件
function __autoload($class)
{
	Zend_Loader::loadClass($class);
}

// 测试版标记
$DEBUG=1; 

// 读取网站配置文件(XML格式)
$conf=new Zend_Config_Xml('./config.xml', null);

// 连接mysql数据库
$db=Zend_Db::factory('PDO_MYSQL', $conf->database->toArray());
$db->query('set names "'.$conf->database->charset.'"'); // default charsets of database
$reg=Zend_Registry::getInstance();
$reg->set('database', $db);

// 开始session
if (!Zend_Session::isStarted())
	Zend_Session::start();

// 用户信息，未登录:login=-1，已登录:login=array(AId, Name, Priv)
if (empty($_SESSION['AId']))
	$reg->set('login', -1);
else
	$reg->set('login', array('AId'=>$_SESSION['AId'],
							'Name'=>$_SESSION['Name'],
							'Priv'=>$_SESSION['Priv'],
							'User'=>$_SESSION['User']));

// 初始化front controller
$front=Zend_Controller_Front::getInstance();
$front->throwExceptions(true);
// $front->setParam('noViewRenderer', true); // disable view helper
$front->setDefaultControllerName('home');
//$front->setParam('useDefaultControllerAlways', true);
$front->setControllerDirectory('./app/controllers');

// helper
$view=new Zend_View(array('encoding'=>'UTF-8'));
$view_render=new Zend_Controller_Action_Helper_ViewRenderer($view);
$view_render->setViewSuffix('php');
Zend_Controller_Action_HelperBroker::addHelper($view_render);

try {
	// 开始运行
	$front->dispatch();
} catch (Exception $e) {
	// 处理异常
	include_once 'exception.php';
}
?>
